﻿<?php
if (!isset($_SESSION["taikhoan"]))
	{
		header("Location: dbcl-dangnhap.php");
	}
  include "connect.php";
  $data = array();
  $kq = 0;
    
  function add_person($mahp,$hknk,$nhom,$siso,$magv)
  {
	  global $data;
	  
	  $data []= array(
		  'mahp' => $mahp,
		  'hknk'=> $hknk,
		  'nhom' => $nhom,
		  'siso' => $siso,
		  'magv'=> $magv,
		  );
	  }
  
	  if ( $_FILES['file']['tmp_name'] )
	  {
		  $dom = DOMDocument::load( $_FILES['file']['tmp_name'] );
		  $rows = $dom->getElementsByTagName( 'Row' );
		  $mssv_row = true;
		  foreach ($rows as $row)
		  {
			  if ( !$mssv_row )
			  {	 
					  $index = 1;
					  $cells = $row->getElementsByTagName( 'Cell' );
					  foreach( $cells as $cell )
					  { 
						  $ind = $cell->getAttribute( 'Index' );
						  if ( $ind != null ) $index = $ind;
						  
						  if ( $index == 1 ) $mahp = $cell->nodeValue;
						  if ( $index == 2 ) $hknk = $cell->nodeValue;
						  if ( $index == 3 ) $nhom = $cell->nodeValue;	
						  if ( $index == 4 ) $siso = $cell->nodeValue;
						  if ( $index == 5 ) $magv = $cell->nodeValue;					  
						  $index += 1;
					  }
					  add_person($mahp,$hknk ,$nhom,$siso,$magv);
			}
			$mssv_row = false;
		}
		$kq = count($data);
  	}
  ?>
  <html>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>upload file</title>
  </head>
  <body>
  <table>
          <tr><td height="50">&nbsp;</td></tr>
  </table>
  <form name="form1" enctype="multipart/form-data" method="post" action="">
    
           <table width="500" align="center" border="0" style="border:1px solid #0066FF" cellspacing="0" >
									
								  <tr> 
										<td height="30" colspan="2" align="center" bordercolor="#FFFFFF" background="image/bg_header.gif">
											<span style="font-size:24px; color:#FFFFFF; font-weight:bold;">Upload file Lớp Học Phần</span></td>
								  </tr>
								  
								  <tr><td height="15" colspan="2" bordercolor="#FFFFFF"></td></tr>
									
								  <tr bordercolor="#FFFFFF" align="center"> 
									  <td  height="30" style="font-size:18px" width="200">File Excel:</td>
									  <td align="left"> <input type="file" name="file" size="40">   </td>
								  </tr>
								  
								  
								  <tr><td height="15" colspan="2" bordercolor="#FFFFFF"></td></tr>
								  
								  <tr bordercolor="#FFFFFF">
									  <td  align="center" height="30" colspan="2"> <input type="submit" name="Submit" value="Import"></td>
								 </tr>
								 <tr><td colspan="2" height="20">&nbsp;</td></tr>
								
			</table>
   
  </form>
  
  <?php 
  	foreach( $data as $row ) 
	{
  		mysql_query( "insert into `lop hoc phan` values('".$row["mahp"]."','".$row["hknk"]."','".$row["nhom"]."','".$row["siso"]."','".$row["magv"]." ')");
	     //echo " '".$row["mahp"]."','".$row["hknk"]."','".$row["nhom"]."','".$row["siso"]."','".$row["magv"]." ' "; 
  	} 	
?>
  
  </body>
  </html>
﻿
   
   
